/**
 * 
 */
package com.neusoft.cmsprojects.action;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.neusoft.cmsprojects.model.TbConfig;
import com.neusoft.cmsprojects.service.BasicSettingsService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * index:		基本设置相关的Action
 * @author guanhaimin
 * date:2014年12月16日下午2:14:27
 */
public class BasicSettingsAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	@Resource(name = "BasicSettingsService")
	private BasicSettingsService basicSettingsService;
	private TbConfig tc;
	private String opt;
	private String content;
	
	/**
	 * index:		网站底部设置
	 * @author guanhaimin
	 * @date 2014年12月24日 下午8:39:13
	 * @return String
	 */
	public String SiteBottomSetting() {
		HttpServletRequest request = ServletActionContext.getRequest();
		opt = "CBOTTOM";
		this.basicSettingsService.getSiteBottomContent();
		request.setAttribute("Opt", opt);
		return "ueditor";
	}
	
	/**
	 * index:		公司简介设置
	 * @author guanhaimin
	 * @date 2014年12月16日 下午3:29:21 void
	 */
	public String CompanyIntroSetting() {
		HttpServletRequest request = ServletActionContext.getRequest();
		opt = "CINTRO";
		this.basicSettingsService.getCompanyIntroduceContent();
		request.setAttribute("Opt", opt);
		return "ueditor";
	}
	
	/**
	 * index:		联系我们内容设置
	 * @author guanhaimin
	 * @date 2014年12月16日 下午3:30:15 void
	 */
	public String ContactSettings() {
		HttpServletRequest request = ServletActionContext.getRequest();
		opt = "CCONTACT";
		this.basicSettingsService.getCompanyContactContent();
		request.setAttribute("Opt", opt);
		return "ueditor";
	}
	
	/**
	 * index:		保存编辑框内容
	 * @author guanhaimin
	 * @throws Exception 
	 * @date 2014年12月17日 下午9:13:38 void
	 */
	public void SaveContent() throws Exception {
		String msg = this.basicSettingsService.saveFile(content, opt);
		if(msg.trim().equals("SaveSuccess")){
			this.basicSettingsService.saveContent(content, opt);
		}
	}
	
	/**
	 * index:		网站基本设置
	 * @author guanhaimin
	 * @throws Exception 
	 * @date 2014年12月16日 下午3:27:58 void
	 */
	public String BasicSettings() throws Exception {
		if(opt != null && opt.trim().equals("SAVE")){
			this.basicSettingsService.updateBasicSettings(tc);
		}else{
			this.basicSettingsService.getBasicSettings();
		}
		return "BasicSettings";
	}
	
	/**
	 * index:		图片上传
	 * @author guanhaimin
	 * @date 2014年12月17日 下午4:10:53 void
	 */
	public void imageUpload() {
		System.out.println("图片上传");
	}
	
	
	
	
	public BasicSettingsService getBasicSettingsService() {
		return basicSettingsService;
	}
	public void setBasicSettingsService(BasicSettingsService basicSettingsService) {
		this.basicSettingsService = basicSettingsService;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public TbConfig getTc() {
		return tc;
	}

	public void setTc(TbConfig tc) {
		this.tc = tc;
	}

	public String getOpt() {
		return opt;
	}

	public void setOpt(String opt) {
		this.opt = opt;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}
}
